<template>
  <div>
    <van-dialog
        v-model="isShow"
        title="选择商机信息"
        show-cancel-button
        :beforeClose="beforColse"
        @confirm="toSave"
        @cancel="isShow = false">
      <van-checkbox-group v-model="result">
        <van-cell-group>
          <van-cell
              v-for="(item) in dataSource"
              clickable
              :key="item.id"
              :title="item.fname"
          >
            <template #right-icon>
              <van-checkbox :name="item" ref="checkboxes" />
            </template>
          </van-cell>
        </van-cell-group>
      </van-checkbox-group>
    </van-dialog>
  </div>
</template>
<script>
import { opportunityList } from "@/api/api";
import {Notify} from "vant";
export default {
  name: 'choosedSjInfo',
  props: {
  },
  data() {
    return {
      isShow: false,
      result: [],
      dataSource: []
    }
  },
  watch: {
  },
  computed: {
  },
  created() {
    opportunityList({
      pageNo: 1,
      pageSize: 10000000
    }).then(res => {
      if(res.success) {
        this.dataSource = res.result.records
      }
    })

  },
  methods: {
    show () {
      this.isShow = true
      this.result = []
    },
    toggle() {
    },
    beforColse (action, done) {
      if (action=='confirm' && this.result.length == 1) {
        done()
      }
      done(false)
    },
    toSave() {
      if (this.result.length != 1) {
        Notify({ type: 'warning', message: '仅可勾选一条数据！' })
        return false
      }
      this.isShow = false
      this.$emit('ok', { result: this.result[0]})
    },
  }

}
</script>
<style scoped>
/deep/.van-dialog__content {
  max-height: 50vh;
  overflow: scroll;
}
</style>